﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Waiter.Controler;
using Waiter.Common;
using Waiter.CustomControl;

namespace Waiter.View
{
    public partial class FrmSales : DevComponents.DotNetBar.Office2007Form
    {
        public FrmSales()
        {
            InitializeComponent();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_INFO, "FrmSales.btnBack_Click", "", "");
            this.Close();
        }

        private void btnRefesh_Click(object sender, EventArgs e)
        {
            CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_INFO, "FrmSales.btnRefesh_Click", "", "");
            this.panTable.Controls.Clear();
            fsLoadAreaList();
        }

        private void FrmSales_Load(object sender, EventArgs e)
        {
            CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_INFO, "FrmSales.FrmSales_Load", "", "");
            fsLoadAreaList();
        }

        public void fsLoadAreaList()
        {
            CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_INFO, "FrmSales.fsLoadAreaList", "", "");
            MasterCtrl masterCtrl = new MasterCtrl();
            List<MASTER> areaList = masterCtrl.fsGetMasterFromGroupCode(CommonConstants.CAC_KHU_VUC);
            if (areaList == null || areaList.Count == 0)
            {
                return;
            }

            int pointX = CommonConstants.AREA_MARGIN;
            int pointY = CommonConstants.AREA_MARGIN;
            int waitPanelWidth = this.panTable.Width - CommonConstants.AREA_MARGIN * 2;

            for (int i = 0; i < areaList.Count; i++)
            {
                AreaItem areaItem = new AreaItem(pointX, pointY, waitPanelWidth);
                areaItem.fsLoadAreaItem(areaList[i]);
                this.panTable.Controls.Add(areaItem);

                pointY += areaItem.Height + CommonConstants.AREA_MARGIN;
            }
            this.SuspendLayout();
        }

        private void headerItem1_Load(object sender, EventArgs e)
        {
            CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_INFO, "FrmSales.headerItem1_Load", "", "");
            this.headerItem1.init("BÁN HÀNG", false);
        }

        public void fsRefreshStatus()
        {
            CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_INFO, "FrmSales.fsRefreshStatus", "", "");
            if (this.panTable.Controls.Count == 0)
            {
                return;
            }
            for (int i = 0; i < this.panTable.Controls.Count; i++)
            {
                AreaItem item = (AreaItem)this.panTable.Controls[i];
                item.fsRefreshAreaItem();
            }
        }
    }
}
